<template>
    <div id="register" style="background-size: 100% 800px" :style="{ backgroundImage: 'url(' + Img + ')' }">
        <div>
            <div class="department">
                <img :src='require("@/assets/images/Logo2.png")' alt="" class="lg_logo" />
                <div class="title">
                    <router-link to="login"> <button class="gray login_title" >登录</button></router-link>
                    /
                    <router-link to="register"><button class="blue register_title" >注册</button></router-link>
                </div>
                <form id="form">
                <!-- 用户名 -->
                <div class="input">
                    <span></span>
                    <div class="fl username">
                    <input type="text" placeholder="用户名" class="t_input" id="uname" v-model="username" @blur="uShow" autocomplete="off"/>
                    </div>
                </div>

                <!-- 用户名的提示 -->
                <div class="piece" v-show="show_user">
                    <div class="tra"></div>
                    <a-icon type="warning" theme="twoTone" two-tone-color="red"/>&nbsp;&nbsp;请将用户名控制在20个字符以内...
                </div>

                <!-- 输入密码 -->
                <div class="input d">
                    <span></span>
                    <div class="fl div">
                    <input type="password" placeholder="输入密码" class="t_input" id="upass" v-model="pw" autocomplete="off"/>
                    </div>
                </div>
                <!-- 再输入密码 -->
                <div class="input d">
                    <span></span>
                    <div class="fl div">
                    <input type="password" placeholder="请再输入密码" class="t_input" @blur="pShow" v-model="rpw" autocomplete="off"/>
                    </div>
                </div>
                <!-- 再输入密码的提示 -->
                <div class="order" v-show="show_pw">
                    <div class="tra"></div>
                    <a-icon type="warning" theme="twoTone" two-tone-color="red"/>&nbsp;&nbsp;&nbsp;两次密码不相同！
                </div>

                <!-- 输入手机号 -->
                <div class="input d">
                    <span></span>
                    <div style="" class="fl div">
                        <input type="text" placeholder="请输入手机号" class="t_input" @blur="checkPhone" maxlength="11" v-model="phone" autocomplete="off"/>
                    </div>
                </div>
                <!-- 手机号提示 -->
                <div class="tel" v-show="show_tel">
                    <div class="tra"></div>
                    <a-icon type="warning" theme="twoTone" two-tone-color="red"/>&nbsp;手机号格式错误!
                </div>

                <!-- 获取和输入验证码 -->
                <div class="input d" >
                    <span></span>
                    <div  class="fl div">
                    <input type="text" placeholder="请输入验证码" class="ticket"  v-model="ticket" autocomplete="off"/>
                    <input type="button" value="验证码" class="code" @click="send" :disabled="Dodisabled" :style="style_un" />
<!--                    <Identify-->
<!--                        labelType="button"-->
<!--                        captchaAppID="2032359745"-->
<!--                    />-->
                    </div>
                </div>
                <!-- 注册按钮 -->
                <input type="button" value="注册" class="btn" @click="regist"/>
                </form>

                <!-- 下缀 -->
                <div class="title-line">
                <span class="tit">使用以下方式登录</span>
                </div>
                <div class="other">
                <span class="sport_qq"><a href="#" class="qq"></a></span>
                <span class="sport"><a href="#" class="wechat"></a></span>
                <span class="sport"><a href="#"></a></span>
                </div>
            </div>
        </div>
        <PageFooter></PageFooter>
    </div>
</template>
<script>
import PageFooter from '../components/PageFooter.vue'
// import Identify from '../components/Identify.vue'

export default {
    name: "Register",
    data() {
        return {
        username: "",
        pw: "",
        rpw: "",
        phone: "",
        ticket:"",
        Img: require('@/assets/images/login.jpg'),
        Dodisabled:true,
        show_user: false,
        show_pw: false,
        show_tel: false,
        style_un:{
            background:'#ccc',
            cursor:'not-allowed'
        }
        };
    },
    components: {
        PageFooter,
        // Identify
    },
    created() {
        //在实例创建完成后被立即调用
    },
    methods: {
        uShow() {
            if (this.username.length > 20 || this.username.length == 0) {
                this.show_user = true;
                this.Dodisabled=false;
            } else {
                this.show_user = false;
            }
        },
        pShow() {
            if (this.pw != this.rpw) {
                this.show_pw = true;
            } else {
                this.show_pw = false;
            }
        },
        checkPhone() {
            const regMobile = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
            if (regMobile.test(this.phone)) {
                this.show_tel = false;
                this.Dodisabled=false;
                this.style_un={};
            } else {
                this.show_tel = true;
            }
        },
        send() {
            if(!this.show_tel){
                this.$axios.get("http://192.168.43.99:8080/sms/send?phone=" + this.phone).then(
                function (response) {
                console.log(response);
                },
                function (error) {
                console.log(error);
                }
        )
            }
            else{
                alert("请重新输入！");
            }
        },
        regist(){
            if(this.username!=""&&this.pw!=""&&this.rpw!=""&&this.phone!=""&&this.ticket!=""&&!this.show_user&&!this.show_pw&&!this.show_tel){
                this.$axios.post("https://pms.xybh.online/register/user",
                {"username":this.username, "password":this.pw,"phone":this.phone,"ticket":this.ticket})
                .then(
                function (response) {
                console.log(response);
                },
                function (error) {
                console.log(error);
                }
        )
            }
            else{
                alert("请重新输入！");
            }
        }
    }
};
</script>
<style scoped>
    .d{
        margin-top: 15px;
    }
    .div{
        border-bottom: 2px solid #666;
    }
    .ticket{
        width: 118px;
    }
    .login_title {
        margin-right: 10px;
    }
    .register_title {
        margin-left: 10px;
    }
    .username {
        border-bottom: 2px solid #666;
    }
    @font-face {
        font-family: "icomoon";
        src: url("../assets/fonts/icomoon.eot?we8owe");
        src: url("../assets/fonts/icomoon.eot?we8owe#iefix")
            format("embedded-opentype"),
            url("../assets/fonts/icomoon.ttf?we8owe") format("truetype"),
            url("../assets/fonts/icomoon.woff?we8owe") format("woff"),
            url("../assets/fonts/icomoon.svg?we8owe#icomoon") format("svg");
        font-weight: normal;
        font-style: normal;
        font-display: block;
    }
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    a {
        text-decoration: none;
        color: black;
    }
    .fl {
        float: left;
    }
    .fr {
        float: right;
    }
    form {
        width: 225px;
        margin: auto auto;
    }
    input {
        outline-style: none;
        border: none;
        background-color:rgba(235,235, 235, .6);
        font-size: 16px;
        color: black;
    }
    #register{
        height: 100%;
        width: 100%;
    }
    .department {
        width: 350px;
        height: 800px;
        background-color:rgba(235,235, 235, .5);
        text-align: center;
    }
    .lg_logo {
        width: 100px;
        height: 100px;
        margin-top: 105px;
    }

    .blue {
        width: 56px;
        height: 36px;
        padding: 0px;
        background: rgba(0,0,0,0.00);
        border-radius: 0px;
        border: none;
        outline: none;
        font-size: 28px;
        font-family: Segoe UI, Segoe UI-Regular;
        font-weight: 400;
        text-align: left;
        color: #00a1ff;
    }
    .gray {
        width: 56px;
        height: 36px;
        padding: 0px;
        background: rgba(0,0,0,0.00);
        border-radius: 0px;
        border: none;
        outline: none;
        font-size: 28px;
        font-family: Segoe UI, Segoe UI-Regular;
        font-weight: 400;
        text-align: left;
        color: #999;
    }
    .title {
        font-size: 28px;
        font-family: Segoe UI, Segoe UI-Regular;
        margin: 35px auto;
    }
    .input {
        width: 250px;
        height: 30px;
    }

    .input span {
        float: left;
        width: 27px;
        height: 27px;
        font-family: "icomoon";
        font-size: 27px;
    }
    .t_input {
        width: 180px;
        height: 24px;
        padding-left: 7px;
    }
    .add {
        height: 19px;
        text-align: center;
    }
    .rem {
        width: 84px;
    }
    .btn {
        width: 175px;
        height: 30px;
        margin-top: 30px;
        background-color: #0e60ff;
        color: white;
    }
    .sport_qq {
        width: 48px;
        height: 48px;
        float: left;
        margin-left: 10px;
        font-family: "icomoon";
        font-size: 36px;
    }
    .sport {
        width: 48px;
        height: 48px;
        float: left;
        margin-left: 58px;
        font-family: "icomoon";
        font-size: 36px;
    }
    .title-line .tit {
        height: 72px;
        line-height: 72px;
        margin: 0 auto;
        padding: 0 10px;
        font-size: 14px;
        text-align: center;
        background-color: #ebebeb;
    }
    .title-line {
        width: 270px;
        height: 36px;
        margin: 0px auto;
        border-bottom: 1px solid #666;
        text-align: center;
    }
    .other {
        width: 280px;
        height: 48px;
        margin: 28px auto 0px;
    }
    .lg_logo {
        width: 100px;
        height: 100px;
        margin-top: 105px;
    }
    .btn {
        width: 175px;
        height: 32px;
        margin-top: 30px;
        background-color: #0e60ff;
        color: white;
    }
    #form {
        position: relative;
    }
    .piece {
        position: absolute;
        left: 218px;
        top: -5px;
        width: 160px;
        height: 60px;
        padding: 5px;
        border: 2px solid transparent;
        border-radius:10px;
        box-shadow: #efefef 5px 5px 5px 5px;
        color: black;
        background-color: #fff;
    }
    .tra {
        position: absolute;
        top: 13px;
        left: -20px;
        width: 0;
        height: 0;
        line-height: 0;
        font-size: 0;
        border: 10px solid transparent;
        border-right-color: #fff;
    }
    .order {
        position: absolute;
        text-align: center;
        left: 218px;
        top: 70px;
        width: 180px;
        height: 40px;
        padding: 5px;
        border: 2px solid transparent;
        border-radius:10px;
        box-shadow: #efefef 5px 5px 5px 5px;
        color: black;
        background-color: #fff;
    }
    .code {
        width: 80px;
        height: 29px;
        background: #00a1ff;
        color: white;
        cursor: pointer;
    }
    .tel {
        position: absolute;
        left: 218px;
        top: 125px;
        width: 160px;
        height: 40px;
        padding: 5px;
        border-radius: 10px;
        border: 2px solid transparent;
        box-shadow: #efefef 5px 5px 5px 5px;
        color: black;
        background-color: #fff;
    }
    .qq{
        color: #0696d0;
    }
    .wechat{
        color: #8de055;
    }
</style>
